<?php

    require_once(__DIR__ . '/../../App/Library/Auth/Auth.php');


    $page = '    <li class="active"> Αγγελίες <span class="divider">/</span>' . $_SESSION['Auth']['UserName'] . ' </li>';

    if ($_GET['id']) {
        $page = '    <li  > <a href="login.php?page=user_panel_aggelies"> Αγγελίες  </a> <span class="divider">/</span> </li>
        <li class="active"> Καταχώρηση νο ' . $_GET['id'] . ' </li>';
    }

    include('info.html');

    $db = MyDB::db();


    if ($_id = $_GET['id']) {

        if (!$_GET['rm']) {
            require_once('show.php');

            return;
        } else {

            $db->where('id',$_id);
            if (!$db->delete("field_data",array( 'id'))) {
                echo 'failed to remove;';
            }

        }
    }

    $_tmp_header = array(
        'id'         => 40,
        'Title'      => 200,
        'Εικόνα'     => 60,
        'Κείμενο'    => 60,
        'Ημερομηνία' => 150,
        'Πουλήθηκε'  => 60,
    );

    $Auth    = Auth::get_info('id');
    $sql     = 'SELECT field_data.*  FROM field_data WHERE auth_id=? limit 0,20';
    $_tmp    = $db->rawQuery($sql, array($Auth));
    $recs    = array();
    $recs_cx = 0;

    foreach ($_tmp as $t) {
        $recs_cx++;

        $recs[$recs_cx]['id'] = $t['id'];
        $title                = !empty($t['var44']) ? $t['var44'] : "χωρίς τίτλο";

        $img     = $t['var54'] ? '<img width="70px;" src="data:image/jpeg;base64,' . base64_encode($t['var54']) . ' " />' : NULL;
        $keimeno = isset($t['var45']) ? $t['var45'] : "χωρίς κείμενο";
        $sold    = $t['var54'] ? "ΝΑΙ" : "OXI";
        $sold = ".";

        $recs[$recs_cx]['Title']      = $title;
        $recs[$recs_cx]['Εικόνα']     = $img;
        $recs[$recs_cx]['Κείμενο']    = $keimeno;
        $recs[$recs_cx]['Ημερομηνία'] = date('m/d/Y', $τ['date_create']);
        $recs[$recs_cx]['Πουλήθηκε']  = $sold;


    }


    echo Html::javascript('jquery.tablesorter.min.js');


    Html_Table::show($_tmp_header, $recs, NULL, " Οι Αγγελίες μου ", TRUE, "login.php?page=user_panel_aggelies&id=", 'Title');


    echo Html_Table::init_tablesorter();
